package dilmaj.client;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Panel;

import dilmaj.shared.StarEntryVO;
import dilmaj.shared.StarSuggestionVO;

public class RemoveHandler implements ClickHandler {
	private StarPanel owner;
	private StarServiceAsync starSvc = GWT.create(StarService.class);
	
	public RemoveHandler(StarPanel owner) {
		this.owner=owner;
	}
	
	AsyncCallback<List<StarEntryVO>> removeCallback=new AsyncCallback<List<StarEntryVO>>() {

		@Override
		public void onFailure(Throwable caught) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onSuccess(List<StarEntryVO> result) {
			// TODO Auto-generated method stub
			DataStore.removeEntry(result);
			owner.getButtonPanel().removeFromParent();
			DataStore.hideWait();
		}
	};
	
	@Override
	public void onClick(ClickEvent event) {
		// TODO Auto-generated method stub
		if (starSvc == null) {
		      starSvc = GWT.create(StarService.class);
		    }
		
		StarEntryVO dataVO=owner.getDataVO();
		DataStore.showWait();
		starSvc.removeEntry(dataVO, removeCallback);
		owner.hide();
		DataStore.closePanel(owner);
	}

}
